package com.team06.mapper;
import com.team06.pojo.Airl;
import com.team06.pojo.BllsBelt;
import com.team06.pojo.Dfdl;
import org.apache.ibatis.annotations.*;
import java.util.Map;
@Mapper
public interface FlightUpdateMapper {
    @Update("UPDATE DFOE_DFDL_FLIGHT " +
            "SET CFNO = #{cfno}, CFTP = #{cftp}, STAT = #{stat} " +
            "WHERE FLNO = #{flno}")
    void updatePlaneByFlno(@Param("flno") String flno,
                           @Param("cfno") String cfno,
                           @Param("cftp") String cftp,
                           @Param("stat") String stat);

//时间
@Update("UPDATE DFOE_DFDL_FLIGHT SET FLNO = #{flno}, FIDE = #{fide}, STAT = #{stat} WHERE FLNO = #{flno}")
void updateFlightBasicInfo(@Param("flno") String flno,
                           @Param("fide") String fide,
                           @Param("stat") String stat);

    @Update("UPDATE DFOE_DFDL_AIRPORT a " +
            "SET FPTT = #{fptt}, FPLT = #{fplt} " +
            "WHERE a.FLIGHT_ID = (SELECT ID FROM DFOE_DFDL_FLIGHT WHERE FLNO = #{flno} AND ROWNUM = 1)")
    void updateAirportTimeInfo(@Param("fptt") String fptt,
                               @Param("fplt") String fplt,
                               @Param("flno") String flno);
//机场信息
@Update("UPDATE MSG_BASE_APUE SET " +
        "APOT_APAT = #{apotApat}, " +
        "APOT_CNNM = #{apotCnnm}, " +
        "APOT_ENNM = #{apotEnnm}, " +
        "APOT_AISO = #{apotAiso}, " +
        "APOT_APSN = #{apotApsn} " +
        "WHERE APOT_CODE = #{apotCode}")  // 移除对 APOT_CODE 本身的更新
void updateAirportInfo(@Param("apotCode") String apotCode,
                       @Param("apotApat") String apotApat,
                       @Param("apotCnnm") String apotCnnm,
                       @Param("apotEnnm") String apotEnnm,
                       @Param("apotAiso") String apotAiso,
                       @Param("apotApsn") String apotApsn);

    @Update("UPDATE MSG_DFME_AIRL SET AIRL_ARPT_ID = #{airlArptId} WHERE DFLT_FLID = #{dfltFlid}")
    void updateairlines(Airl airl);

    @Select("SELECT AIRL_ARPT_ID FROM MSG_DFME_AIRL WHERE DFLT_FLID = #{dfltFlid}")
    String getOldAirlArptId(Integer dfltFlid);

    @Select("SELECT DFLT_FLID, AIRL_ARPT_ID, PENDING_AIRL_ARPT_ID, APPROVAL_STATUS FROM MSG_DFME_AIRL WHERE DFLT_FLID = #{dfltFlid} LIMIT 1")
    @Results({
            @Result(property = "dfltFlid", column = "DFLT_FLID"),
            @Result(property = "airlArptId", column = "AIRL_ARPT_ID"),
            @Result(property = "pendingAirlArptId", column = "PENDING_AIRL_ARPT_ID"),
            @Result(property = "approvalStatus", column = "APPROVAL_STATUS")
    })
    Airl getAirlWithPending(Integer dfltFlid);
    @Update("UPDATE MSG_DFME_AIRL SET PENDING_AIRL_ARPT_ID = #{pendingAirlArptId}, APPROVAL_STATUS = 'PENDING' WHERE DFLT_FLID = #{dfltFlid}")
    void submitAirlChangeForApproval(Airl airl);
    @Update("UPDATE MSG_DFME_AIRL SET AIRL_ARPT_ID = #{airlArptId}, APPROVAL_STATUS = 'APPROVED', PENDING_AIRL_ARPT_ID = NULL WHERE DFLT_FLID = #{dfltFlid}")
    void approveAirlChange(Airl airl);
    @Update("UPDATE MSG_DFME_AIRL SET APPROVAL_STATUS = 'REJECTED', PENDING_AIRL_ARPT_ID = NULL WHERE DFLT_FLID = #{dfltFlid}")
    void rejectAirlChange(Airl airl);
    @Update("UPDATE DFME_BLLS_BELT " +
            "SET BTNO = #{btno}, " +
            "CODE = #{code}, " +
            "ESTR = #{estr}, " +
            "EEND = #{eend}, " +
            "RSTR = #{rstr}, " +
            "REND = #{rend} " +
            "WHERE BELT_ID = (SELECT BLLS_BELT_ID FROM MSG_DFME_BLLS WHERE DFLT_FLID = #{dfltFlid} LIMIT 1)")
    void updateBllsBeltFieldsByDfltFlid(@Param("dfltFlid") String dfltFlid,
                                        @Param("btno") String btno,
                                        @Param("code") String code,
                                        @Param("estr") String estr,
                                        @Param("eend") String eend,
                                        @Param("rstr") String rstr,
                                        @Param("rend") String rend);
    @Update("UPDATE MSG_DFME_GTLS " +
            "SET GTNO = #{gtno}, " +
            "CODE = #{code}, " +
            "BTSC = #{btsc}, " +
            "RSTR = #{rstr}, " +
            "REND = #{rend} " +
            "WHERE DFLT_FLID = #{dfltFlid}")
    void updateGtlGateFieldsByDfltFlid(@Param("dfltFlid") String dfltFlid,
                                       @Param("gtno") String gtno,
                                       @Param("code") String code,
                                       @Param("btsc") String btsc,
                                       @Param("rstr") String rstr,
                                       @Param("rend") String rend);


}
